﻿using Domain.Flow;
using MediatR;
using U.B.ErrorCode;
using U.B.ReadApi.Command.Raddit.BW;
using U.B.Repistory;

namespace U.B.ReadApi.CommandHander.Raddit.BWHA
{
    public class GetFarmCommandHander : IRequestHandler<GetFarmCommand, ApiResult<Farm>>
    {
        public IRepistory<Farm> _FarmRepository;

        public GetFarmCommandHander(IRepistory<Farm> FarmRepository)
        {
            _FarmRepository = FarmRepository;
        }
        /// <summary>
        /// 养殖信息反填
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<ApiResult<Farm>> Handle(GetFarmCommand request, CancellationToken cancellationToken)
        {
            ApiResult<Farm> apiResult = new ApiResult<Farm>();
            var result = _FarmRepository.GetAll().FirstOrDefault(x => x.BatchNo == request.BatchNo);
            apiResult.code = Renum.显示成功;
            apiResult.Data = result;
            apiResult.Message = Renum.显示成功.ToString();
            return Task.FromResult(apiResult);
        }
    }
}
